package com.zqs.controller;

import com.zqs.entity.Collect;
import com.zqs.service.CollectService;
import com.zqs.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 收藏页
 */
@CrossOrigin
@RestController
@RequestMapping("collects")
public class CollectController extends BaseController{

    @Autowired
    private CollectService collectService;

    // 添加汽车到收藏列表 json{pid}
    @GetMapping("add_product")
    public JsonResult<Void> addProduct(Integer pid,HttpSession session){
        collectService.addProductInCollect(pid,getSessionUid(session));
        return new JsonResult<>(OK);
    }

    // 根据用户id查收藏商品 不用传参
    @GetMapping("get_by_uid")
    public JsonResult<List<Collect>> getByUid(HttpSession session){
        List<Collect> datalist = collectService.getUidCollect(getSessionUid(session));
        return new JsonResult<>(OK,datalist);
    }

    // 根据收藏商品id更改车辆状态  参数：id
    @GetMapping("update_state")
    public JsonResult<Void> updateState(Integer id,HttpSession session){
        collectService.updateStateById(id, getSessionUid(session));
        return new JsonResult<>(OK);
    }
}
